package com.sls.game.dao.xingxitian.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.impl.SuperDAO;
import com.sls.game.dao.xingxitian.XingDisCountDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.xingqitian.XingDisCountInfo;

/**
 * 
 * @description
 * @author Wangxuegang
 * @date 2012-12-22
 */
@Repository("xingDisCountDAO")
public class XingDisCountDAOImpl extends SuperDAO<XingDisCountInfo> implements
		XingDisCountDAO {

	@Override
	public void insert(XingDisCountInfo info) {
		this.getSqlSession().insert("mybatis.xml.XingDiscountMapper.insert",
				info);

	}

	@Override
	public XingDisCountInfo queryDisCountInfoByGoodsId(String originalGoodsId) {
		XingDisCountInfo info = null;
		info = this.getSqlSession().selectOne(
				"mybatis.xml.XingDiscountMapper.queryDisCountInfoByGoodsId",
				originalGoodsId);

		return info;
	}

	@Override
	public Pagination<XingDisCountInfo> queryDiscountInfo(XingDisCountInfo info) {
		Pagination<XingDisCountInfo> paginationList = null;
		Integer rowCount = queryRowCount(info);
		info.calculate();
		List<XingDisCountInfo> list = queryParvalueInfoList(info);
		paginationList = this.queryPagination(rowCount, list, info);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private Integer queryRowCount(XingDisCountInfo info) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.XingDiscountMapper.queryRowCount", info);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private List<XingDisCountInfo> queryParvalueInfoList(XingDisCountInfo info) {
		List<XingDisCountInfo> list = this
				.getSqlSession()
				.selectList(
						"mybatis.xml.XingDiscountMapper.queryXQTDiscountInfoList",
						info);
		return list;
	}

	@Override
	public List<XingDisCountInfo> queryDiscountByProductId(String productId) {
		List<XingDisCountInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.XingDiscountMapper.queryDiscountByProductId",
				productId);

		return list;
	}

	@Override
	public List<String> queryIdsByProductId(String productId) {
		List<String> list = this.getSqlSession()
				.selectList(
						"mybatis.xml.XingDiscountMapper.queryIdsByProductId",
						productId);
		return list;
	}

	@Override
	public void updateSalePrice(XingDisCountInfo info) {
		this.getSqlSession().update(
				"mybatis.xml.XingDiscountMapper.updateSalePrice", info);

	}

	/**
	 * 记录详情
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public XingDisCountInfo queryDiscountInfoById(String id) {
		XingDisCountInfo info = null;
		info = this.getSqlSession().selectOne(
				"mybatis.xml.XingDiscountMapper.queryDiscountInfoById", id);
		return info;
	}

}
